[AI] Add host model cache API surface#4302
Conversation
The VM model-cache feature needs persistent schema rows and generated client surfaces before premium can expose scheduling and cache-management controls. Resolves: ZSTAC-0 Change-Id: I424f987899216872309b42439f8ba8a1353ae505
|
Warning Review limit reached
More reviews will be available in 10 minutes. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (21)
Warning
|
| Layer / File(s) | Summary |
|---|---|
新增 AI Host Model Cache 核心表 conf/db/upgrade/V5.5.28__schema.sql |
新增 AiHostModelCacheVO(缓存元数据/状态/引用计数)、AiHostCacheStorageVO(存储容量与水位)、AiHostModelCachePolicyVO(策略配置)、AiHostModelCacheReservationVO(缓存预留记录)四张表,均含联合唯一约束/索引及对 HostEO(hostUuid) 的外键级联删除约束。 |
VmModelMountVO 关联缓存表 conf/db/upgrade/V5.5.28__schema.sql |
为 VmModelMountVO 新增可空列 cacheUuid,创建索引 idxVmModelMountVOCacheUuid,并添加外键 fkVmModelMountVOAiHostModelCacheVO,当 AiHostModelCacheVO 记录被删除时将 cacheUuid 置空(SET NULL)。 |
Estimated code review effort
🎯 2 (Simple) | ⏱️ ~10 分钟
Poem
🐇 小兔翻开数据库的土地,
种下四张崭新的缓存表,
HostUuid 像根绳紧紧相系,
VmModelMount 轻轻指向缓存桥,
删之则空,聚则有序,
AI 模型的家园悄然筑起! 🌱
Important
Pre-merge checks failed
Please resolve all errors before merging. Addressing warnings is optional.
❌ Failed checks (1 error)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Title check | ❌ Error | 标题不符合指定格式要求,缺少类型前缀(type)。格式应为 [scope]: ,但当前为 [AI] Add host model cache API surface。 | 修改标题格式为 [scope]: 的形式,例如 'feat[AI]: Add host model cache API surface',并确保不超过72字符。 |
✅ Passed checks (4 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description check | ✅ Passed | 提供的描述与变更集相关,说明了所做更改的目的和验证方式。 |
| Docstring Coverage | ✅ Passed | No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. |
| Linked Issues check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
| Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
✨ Finishing Touches
🧪 Generate unit tests (beta)
- Create PR with unit tests
- Commit unit tests in branch
sync/ye.zou/feature/ai-host-model-cache-control-plane@@3
Comment @coderabbitai help to get the list of available commands and usage tips.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
conf/db/upgrade/V5.5.28__schema.sql (1)
198-200: ⚡ Quick win存储过程参数中的表名/列名也建议使用反引号
当前
ADD_COLUMN/CREATE_INDEX/ADD_CONSTRAINT的标识符参数是裸字符串;按仓库 SQL 规范,表名与列名应统一使用反引号包裹,避免关键字冲突或后续迁移不一致。As per coding guidelines: “所有表名和列名必须使用反引号包裹(例如:WHERE
system= 1),以避免 MySQL 8.0 / GreatSQL 保留关键字冲突导致的语法错误”。建议修复示例
-CALL ADD_COLUMN('VmModelMountVO', 'cacheUuid', 'VARCHAR(32)', 1, NULL); -CALL CREATE_INDEX('VmModelMountVO', 'idxVmModelMountVOCacheUuid', 'cacheUuid'); -CALL ADD_CONSTRAINT('VmModelMountVO', 'fkVmModelMountVOAiHostModelCacheVO', 'cacheUuid', 'AiHostModelCacheVO', 'uuid', 'SET NULL'); +CALL ADD_COLUMN('`VmModelMountVO`', '`cacheUuid`', 'VARCHAR(32)', 1, NULL); +CALL CREATE_INDEX('`VmModelMountVO`', '`idxVmModelMountVOCacheUuid`', '`cacheUuid`'); +CALL ADD_CONSTRAINT('`VmModelMountVO`', '`fkVmModelMountVOAiHostModelCacheVO`', '`cacheUuid`', '`AiHostModelCacheVO`', '`uuid`', 'SET NULL');🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@conf/db/upgrade/V5.5.28__schema.sql` around lines 198 - 200, All table names and column names in the stored procedure calls ADD_COLUMN, CREATE_INDEX, and ADD_CONSTRAINT must be wrapped with backticks to comply with the repository's SQL coding standards and avoid conflicts with MySQL reserved keywords. Wrap the following identifiers with backticks: 'VmModelMountVO', 'cacheUuid', 'idxVmModelMountVOCacheUuid', and 'AiHostModelCacheVO' in all three procedure calls. This ensures consistency with the repository's SQL naming conventions and prevents potential syntax errors with database engines like MySQL 8.0 or GreatSQL.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@conf/db/upgrade/V5.5.28__schema.sql`:
- Around line 104-105: Remove the DEFAULT NULL clause and change these columns
to NOT NULL for all affected tables: `hostUuid` must be NOT NULL to enable
proper foreign key cascade deletion protection, and columns that are part of
unique constraints (identityHash and sourceRoot in their respective unique keys)
must also be NOT NULL to prevent MySQL from allowing multiple NULL values which
would violate the unique constraint semantics. Apply this change to hostUuid at
lines 104 and 127, and to identityHash/sourceRoot columns in their respective
unique key definitions throughout the schema file at the locations indicated.
---
Nitpick comments:
In `@conf/db/upgrade/V5.5.28__schema.sql`:
- Around line 198-200: All table names and column names in the stored procedure
calls ADD_COLUMN, CREATE_INDEX, and ADD_CONSTRAINT must be wrapped with
backticks to comply with the repository's SQL coding standards and avoid
conflicts with MySQL reserved keywords. Wrap the following identifiers with
backticks: 'VmModelMountVO', 'cacheUuid', 'idxVmModelMountVOCacheUuid', and
'AiHostModelCacheVO' in all three procedure calls. This ensures consistency with
the repository's SQL naming conventions and prevents potential syntax errors
with database engines like MySQL 8.0 or GreatSQL.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: http://open.zstack.ai:20001/code-reviews/zstack-cloud.yaml (via .coderabbit.yaml)
Review profile: CHILL
Plan: Pro
Run ID: 3af6b300-8d45-46a2-8818-bb73ee532b92
⛔ Files ignored due to path filters (19)
sdk/src/main/java/SourceClassMap.javais excluded by!sdk/**sdk/src/main/java/org/zstack/sdk/AiHostCacheStorageInventory.javais excluded by!sdk/**sdk/src/main/java/org/zstack/sdk/AiHostCacheStorageStatus.javais excluded by!sdk/**sdk/src/main/java/org/zstack/sdk/AiHostModelCacheFailureCode.javais excluded by!sdk/**sdk/src/main/java/org/zstack/sdk/AiHostModelCacheFailurePhase.javais excluded by!sdk/**sdk/src/main/java/org/zstack/sdk/AiHostModelCacheInventory.javais excluded by!sdk/**sdk/src/main/java/org/zstack/sdk/AiHostModelCachePolicyInventory.javais excluded by!sdk/**sdk/src/main/java/org/zstack/sdk/AiHostModelCacheStatus.javais excluded by!sdk/**sdk/src/main/java/org/zstack/sdk/CleanAiHostModelCacheAction.javais excluded by!sdk/**sdk/src/main/java/org/zstack/sdk/CleanAiHostModelCacheResult.javais excluded by!sdk/**sdk/src/main/java/org/zstack/sdk/GetAiHostModelCacheCapacityAction.javais excluded by!sdk/**sdk/src/main/java/org/zstack/sdk/GetAiHostModelCacheCapacityResult.javais excluded by!sdk/**sdk/src/main/java/org/zstack/sdk/QueryAiHostModelCacheAction.javais excluded by!sdk/**sdk/src/main/java/org/zstack/sdk/QueryAiHostModelCacheResult.javais excluded by!sdk/**sdk/src/main/java/org/zstack/sdk/RefreshAiHostModelCacheAction.javais excluded by!sdk/**sdk/src/main/java/org/zstack/sdk/RefreshAiHostModelCacheResult.javais excluded by!sdk/**sdk/src/main/java/org/zstack/sdk/UpdateAiHostModelCachePolicyAction.javais excluded by!sdk/**sdk/src/main/java/org/zstack/sdk/UpdateAiHostModelCachePolicyResult.javais excluded by!sdk/**sdk/src/main/java/org/zstack/sdk/VmModelMountInventory.javais excluded by!sdk/**
📒 Files selected for processing (2)
conf/db/upgrade/V5.5.28__schema.sqltestlib/src/main/java/org/zstack/testlib/ApiHelper.groovy
Host model cache identity and reservation lifecycle fields must be non-null to keep database uniqueness and capacity accounting consistent with the premium VO model. Resolves: ZSTAC-0 Change-Id: Ibbc18ef1436e3ec8366b38c055451fc610fff88a
host cache storage and policy rows are keyed by hostUuid/sourceRoot and are removed through host cascade, so the DDL now rejects null key components instead of relying on nullable unique-key behavior. Resolves: ZSTAC-0 Change-Id: If75425fc43b3ba407b807c7440fe1982b376cf9e
Regenerated ApiHelper after adding host model cache API actions. Resolves: ZSTAC-0 Change-Id: Ic04457599d0e3d3e59d26a7a22156b6785d3e913
6ea6aeb to
7c888ad
Compare
Regenerated SDK in verify-case with the premium host model cache branch mounted so update_sdk stays clean. Tested: verify-case ./runMavenProfile premium Tested: verify-case ./runMavenProfile sdk Resolves: ZSTAC-0 Change-Id: I42c8e3c0edc320588097236dc8d207ebfcb8cdce
Summary
Scope
Verification
Related premium/utility MRs use the same source branch suffix @@3.
sync from gitlab !10260